home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / QUI / UTI / Premier Plug-In Kit 1.0.cpt / Premier Plug-In Kit 1.0 / MPW Examples / .a / BW.a next >
Text File  |  1992-03-04  |  2KB  |  84 lines

  1. ; Routine to Convert a GWorld to Black & White
  2. ;
  3. ; © 1991 Adobe Systems Inc.
  4. ; written by Randy Ubillos
  5. ;
  6. ; NOTE: this routine is called in 32-bit mode!
  7.  
  8.     MACHINE    MC68020
  9.  
  10. ; void BW(Ptr srcpix, Ptr dstpix, short height, short rowBytes, Ptr lookup, Ptr repeat);
  11.  
  12. BWFrame    RECORD    {A6Link},DECR
  13. repeat    ds.l    1
  14. lookup    ds.l    1
  15. rowBytes    ds.l    1
  16. height    ds.l    1
  17. dstpix    ds.l    1
  18. srcpix    ds.l    1
  19.  
  20. Return    ds.l    1
  21. A6Link    ds.l    1
  22.  
  23. LocalSize    equ    *
  24.     ENDR
  25.  
  26. ;---- Local register usage
  27. ; a0 = src pix
  28. ; a1 = dst pix
  29. ; a2 = lookup table
  30. ; a3 = lookup table + 256
  31. ; a4 = lookup table + 512
  32. ; a5 = repeat table
  33. ;
  34. ; d0 = work
  35. ; d1 = work
  36. ; d2 = row counter
  37. ; d3 = rowBytes
  38. ; d4 = height
  39.  
  40. BW    PROC    export
  41.     WITH    BWFrame
  42.     link    a6,#LocalSize
  43.     movem.l    a0-a5/d0-d4,-(sp)        ; save the registers
  44.     
  45.     move.l    srcpix(a6),a0        ; a0 = srcpix
  46.     move.l    dstpix(a6),a1        ; a1 = dstpix
  47.     move.l    rowBytes(a6),d3
  48.     lsr.l    #2,d3            ; d3 = rowLongs
  49.     move.l    height(a6),d4        ; d4 = height
  50.     move.l    lookup(a6),a2        ; a2 = red lookup
  51.     move.l    a2,a3
  52.     add.w    #256,a3            ; a3 = green lookup
  53.     move.l    a2,a4
  54.     add.w    #512,a4            ; a4 = blue lookup
  55.     move.l    repeat(a6),a5        ; a5 = repeat lookup
  56.     
  57.     moveq    #0,d0            ; zero some temps
  58.     moveq    #0,d1
  59.     bra.s    lineend
  60.     
  61. linestart    move.l    d3,d2            ; start the row counter
  62.     bra.s    rowend
  63.     
  64. rowstart    addq    #1,a0            ; skip alpha channel
  65.     move.b    (a0)+,d0            ; get red byte
  66.     move.b    0(a2,d0.w),d1        ; lookup fraction
  67.     move.b    (a0)+,d0            ; get blue byte
  68.     add.b    0(a3,d0.w),d1        ; add in fraction
  69.     move.b    (a0)+,d0            ; get green byte
  70.     add.b    0(a4,d0.w),d1        ; now we have gray value
  71.     move.l    (a5,d1*4),(a1)+        ; save 4 of them
  72. rowend    dbra    d2,rowstart            ; do all pixels
  73.  
  74. lineend    dbra    d4,linestart        ; do all lines
  75.     
  76.     movem.l    (sp)+,a0-a5/d0-d4        ; all done
  77.     unlk    a6
  78.     rts
  79.  
  80.     ENDWITH
  81.     ENDP
  82.     
  83.     END
  84.